import { Inject, Post, Query } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { CommunityTagEntity } from '../../entity/tag';
import { CommunityTagService } from '../../service/tag';

/**
 * 社区标签
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: CommunityTagEntity,
  service: CommunityTagService,
  pageQueryOp: {
    keyWordLikeFields: ['a.name'],
    fieldEq: ['a.status'],
    where: async ctx => {
      const { orderValueStart, orderValueEnd } = ctx.request.body;
      const where: any = [];
      if (orderValueStart) {
        where.push(`a.orderValue >= ${orderValueStart}`);
      }
      if (orderValueEnd) {
        where.push(`a.orderValue <= ${orderValueEnd}`);
      }
      return where;
    },
  },
})
export class AdminCommunityTagController extends BaseController {
  @Inject()
  communityTagService: CommunityTagService;
}
